module.exports.getStore   B
last analyzed

Complexity

Conditions 7
Paths 6

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 7
eloc 15
c 2
b 0
f 0
nc 6
dl 0
loc 23
rs 8
nop 1
1
const ModelStore = require('../../model/catering/store')
2
const Redis = require('../../libraries/redis')
3
const Constant = require('../../libraries/constant')
4
const _ = require('underscore')
5
6
module.exports = {
7
    getStore: async function (id) {
8
        let cacheKey = Constant.STORE_INFO + id
9
        let result = await Redis.get(cacheKey)
10
        if (_.isEmpty(result)) {
11
            result = await ModelStore.first(id)
12
            if (_.isEmpty(result)) return false
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
13
            
14
            result.preview_thumb = result.thumb
15
            result.preview_license = result.license
16
            if (result.thumb && result.thumb.indexOf('http') < 0) result.preview_thumb = ConfigOss.catering.view_server + result.thumb + '?x-oss-process=style/preview'
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable ConfigOss seems to be never declared. If this is a global, consider adding a /** global: ConfigOss */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
17
            if (result.license && result.license.indexOf('http') < 0) result.preview_license = ConfigOss.catering.view_server + result.preview_license + '?x-oss-process=style/preview'
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
18
            
19
            // set Cache
20
            await Redis.set(cacheKey, JSON.stringify(result))
21
        } else {
22
            result = JSON.parse(result)
23
        }
24
25
        // 每次拿都刷新时间
26
        await Redis.expire(cacheKey, Constant.EXPIRE_REFRESH)
27
28
        return result
29
    },
30
31
}
32